/*
 * E-UAE - The portable Amiga Emulator
 *
 * Support for traps
 *
 * Copyright Richard Drummond 2005
 *
 * Based on code:
 * Copyright 1995, 1996 Bernd Schmidt
 * Copyright 1996 Ed Hanway
 */

#pragma once

/*
 * Data passed to a trap handler
 */
typedef struct TrapContext TrapContext;

#define TRAPFLAG_NO_REGSAVE 1
#define TRAPFLAG_NO_RETVAL 2
#define TRAPFLAG_EXTRA_STACK 4
#define TRAPFLAG_DORET 8
#define TRAPFLAG_UAERES 16

/*
 * A function which handles a 68k trap
 */
typedef uint (REGPARAM3 * TrapHandler)(TrapContext*) REGPARAM;

/*
 * Interface with 68k interpreter
 */
extern void REGPARAM3 m68k_handle_trap(uint trap_num) REGPARAM;

uint define_trap(TrapHandler handler_func, int flags, const TCHAR* name);
uae_ptr find_trap(const TCHAR* name);

/*
 * Call a 68k Library function from an extended trap
 */
extern uint CallLib(TrapContext* context, uae_ptr library_base, short func_offset);
extern uint CallFunc(TrapContext* context, uae_ptr func);

/*
 * Initialization
 */
void init_traps();
void init_extended_traps();

#define deftrap(f) define_trap((f), 0, L"")
#define deftrap2(f, mode, str) define_trap((f), (mode), (str))
#define deftrapres(f, mode, str) define_trap((f), (mode | TRAPFLAG_UAERES), (str))